home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / qtawk / wordfreq.exp < prev   
Text File  |  1990-02-10  |  962b  |  37 lines

  1. # wordfreq - print number of occurrences of each word
  2. # input: text
  3. # output: number-word pairs sorted by number
  4.  
  5. BEGIN {
  6.     min_cnt = 1;    # define minimum number of occurrances to print
  7.     min_lng = 3;    # define minimum length of word to count
  8.     comment_only = /^#/;
  9. }
  10.  
  11. # Ignore Comment Only Lines
  12. comment_only { next; }
  13.  
  14.     {
  15.     fprintf("stderr","%u\n",FNR);
  16.     gsub(/{_p}/,"");    #remove puncutation
  17.     gsub(/#.*$/,"");    # remove comments
  18.     gsub(/[0-9+^"'`*\$\&~\<\>=\\\/\[\]\(\)\{\}-]+/," ");   # change to single white space
  19.     for ( i = 1 ; i <= NF ; i++ ) if ( length($i) > min_lng ) count[$i]++;
  20. }
  21.  
  22. FINAL {
  23.     local i = 0, k = 0, m = 0, w;
  24.  
  25.     for ( w in count ) {
  26.     if ( min_cnt <= (j = count[w]) ) {
  27.         print j , w;
  28.         i++;
  29.         m += j;
  30.     }
  31.     k++;
  32.     }
  33.     deletea count;
  34.     printf("File: %s\n",FILENAME);
  35.     printf("Total Words: %lu\nTotal Output: %lu\nTotal Count Ouput: %lu\n\n",k,i,m);
  36. }
  37.